import Vue from "vue";
import Router from "vue-router";

const Login = () => import(/* webpackChunkName: "index" */ '../components/login.vue')
const Home = () => import(/* webpackChunkName: "index" */ '../components/Home.vue')
const loginReg = () => import(/* webpackChunkName: "index" */ '../components/loginReg.vue')
const sharePage = () => import(/* webpackChunkName: "index" */ '../components/sharePage.vue')

const System = () => import(/* webpackChunkName: "system" */ '../components/system.vue')
const message = () => import(/* webpackChunkName: "system" */ '../components/system/message.vue')
const mine = () => import(/* webpackChunkName: "system" */ '../components/system/mine.vue')
const searchPage = () => import(/* webpackChunkName: "system" */ '../components/system/searchPage.vue')

const notFound = () => import(/* webpackChunkName: "errorPage" */ '../components/notFound.vue')
const forbidden = () => import(/* webpackChunkName: "errorPage" */ '../components/forbidden.vue')

const console = () => import(/* webpackChunkName: "console" */ '../components/console.vue')
const managePage = () => import(/* webpackChunkName: "console" */ '../components/management/managePage.vue')

const purviewManage = () => import(/* webpackChunkName: "management" */ '../components/management/purviewManage.vue')
const purviewManageList = () => import(/* webpackChunkName: "management" */ '../components/management/purviewManageList.vue')
const userManage = () => import(/* webpackChunkName: "management" */ '../components/management/userManage.vue')
const menuManage = () => import(/* webpackChunkName: "management" */ '../components/management/menuManage.vue')
const journalManage = () => import(/* webpackChunkName: "management" */ '../components/management/journalManage.vue')
const noticeManage = () => import(/* webpackChunkName: "management" */ '../components/management/noticeManage.vue')

const ownFile = () => import(/* webpackChunkName: "systemFile" */ '../components/system/file/ownFile.vue')
const recycleBin = () => import(/* webpackChunkName: "systemFile" */ '../components/system/file/recycleBin.vue')
const cooperate = () => import(/* webpackChunkName: "systemFile" */ '../components/system/file/cooperate.vue')
const teamDetail = () => import(/* webpackChunkName: "systemFile" */ '../components/system/file/teamDetail.vue')
// const recent = () =>import(/* webpackChunkName: "systemFile" */ '../components/system/file/recent.vue')
const usual = () => import(/* webpackChunkName: "systemFile" */ '../components/system/file/usual.vue')
const fileCategoryList = () => import(/* webpackChunkName: "systemFile" */ '../components/system/file/fileCategoryList.vue')

const recent = () => import(/* webpackChunkName: "lessen" */ '../components/system/file/recent.vue')
const onlineStudy = () => import(/* webpackChunkName: "lessen" */ '../components/system/lessen/onlineStudy.vue')
const video = () => import(/* webpackChunkName: "lessen" */ '../components/system/lessen/onlineStudy/video.vue')
const exam = () => import(/* webpackChunkName: "lessen" */ '../components/system/lessen/onlineStudy/exam.vue')
const history = () => import(/* webpackChunkName: "lessen" */ '../components/system/lessen/onlineStudy/history.vue')

// const islogin = () => import(/* webpackChunkName: "visitor" */ '../components/visitor/islogin.vue')
// const commonMine = () => import(/* webpackChunkName: "visitor" */ '../components/student/commonMine.vue')
// import stuchart from "../components/system/datacharts/stuchart.vue"
// import storageChart from "../components/system/datacharts/storageChart"
import resourceChart from "../components/system/datacharts/resourceChart"
import text from "../components/system/datacharts/text.vue"

const question = () => import(/* webpackChunkName: "staff" */ '../components/system/teacher/question.vue')
const questionList = () => import(/* webpackChunkName: "staff" */ '../components/system/teacher/questionList.vue')

// import detail from "../components/system/datacharts/detail.vue"
const commonSystem = () => import(/* webpackChunkName: "staff" */ '../components/student/commonSystem.vue')

Vue.use(Router);

const router = new Router({
  // mode: "history",
  routes: [
    {
      path: "/",
      redirect: "/home",
    },
    {
      path: "/home",
      component: Home,
      meta: {
        index: 1,
      }
    },
    {
      path: "/login",
      component: Login,
      meta: {
        index: 2
      }
    },
    {
      path: "/system",
      component: System,
      meta: {
        index: 3,
      },
      name: 'system',
      redirect: { path: '/system/mine' },
      children: [
        {
          path: '/system/mine',
          component: mine,
        },
        {
          path: '/system/searchPage',
          component: searchPage,
        },
        {
          path: '/system/file/ownFile', component: ownFile,
          //  meta: {
          //   activeMenu: '/file'
          // }
        },
        { path: '/system/file/recycleBin', component: recycleBin },
        { path: '/system/file/cooperate', component: cooperate },
        { path: '/system/file/recent', component: recent },
        { path: '/system/file/usual', component: usual },
        { path: '/system/file/fileCategoryList', component: fileCategoryList },
        // { path: '/system/datacharts/stuchart', component: stuchart },
        // { path: '/system/datacharts/storageChart', component: storageChart },
        { path: '/system/datacharts/resourceChart', component: resourceChart },
        { path: '/system/datacharts/text', component: text },
        { path: '/system/teacher/question', component: question },
        { path: '/system/teacher/questionList', component: questionList },
        // { path: '/system/datacharts/detail', component: detail },
        {
          path: "/system/lessen/onlineStudy",
          component: onlineStudy,
          redirect: { path: '/system/lessen/onlineStudy/video' },
          children:[
            { path: '/system/lessen/onlineStudy/video', component: video },
            { path: '/system/lessen/onlineStudy/exam', component: exam},
            { path: '/system/lessen/onlineStudy/history', component: history,name:"history"}
          ]
        },
      ]
    },
    { path: '/system/message', component: message },
    {
      path: "/loginReg",
      component: loginReg
    },
    {
      path: "/sharePage",
      component: sharePage,
      name: 'sharePage',
      meta:{
        title:'文件分享'
      }
    },
    {
      path: "/system/file/teamDetail",
      component: teamDetail,
      name: 'teamDetail',
      meta:{
        title:'协作组详情页'
      }
    },
    {
      path: '/console',
      component: console,
      meta: {
        index: 4,
        title:'教学资源管理控制台'
      },
      redirect: '/management/managePage',
      children: [
        {
          path: "/management/managePage",
          component: managePage
        },
        {
          path: "/management/userManage",
          component: userManage
        },
        {
          path: "/management/menuManage",
          component: menuManage
        },
        {
          path: "/management/purviewManage",
          component: purviewManage
        },
        {
          path: "/management/purviewManageList",
          component: purviewManageList
        },
        {
          path: "/management/journalManage",
          component: journalManage
        },
        {
          path: "/management/noticeManage",
          component: noticeManage
        },
      ]
    },
    
    {
      path: '*',
      component: notFound
    },
    {
      path: '/forbidden',
      component: forbidden
    },
    // {
    //   path: '/student/commonSystem',
    //   component: commonSystem,
    //   redirect: { path: '/student/commonMine' },
    //   children:[
    //     { path: '/student/commonMine',component:commonMine},
    //     {
    //       path: '/visitor/islogin',
    //       component: islogin
    //     },
    //   ]
    // }
  ]
});



// 添加路由守卫
router.beforeEach((to, from, next) => {
  //next()放行
  if (to.path === '/loginReg'|| '/home' || '/forbidden' || '*' ||'/student/commonSystem') return next()
  //从sessionStorage中获取保存的token值
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) {
    return next('/forbidden')
  }
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next()
})

export default router